﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;


namespace UtilReportOMS
{
    public class RptManager
    {
        Popup pop= new Popup();
        Uc_Trinhky uc;
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Popup
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToPopup(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly)
        {
            Popup pop = new Popup();
            pop.PlacementTarget = sender;  
            Uc_Trinhky uc = new Uc_Trinhky(pop, sender);
            uc.setinfor(rpttam, dvqly);
            showReportToPopUp(pop,uc);
            sender.IsEnabled = false;            
        }
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Popup
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToPopup(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly, string[] FieldsNames, string[] Formulas)
        {
            Popup pop = new Popup();
            pop.PlacementTarget = sender;  
            Uc_Trinhky uc = new Uc_Trinhky(pop,sender);
            uc.setinfor(rpttam, dvqly,FieldsNames,Formulas);
            showReportToPopUp(pop,uc);
            sender.IsEnabled = false;            
        }

        private static void showReportToPopUp(Popup pop,Uc_Trinhky uc)
        {                        
            uc.Margin = new Thickness(2, 2, 2, 2);
            GradientStopCollection graCollec= new GradientStopCollection();
            graCollec.Add(new GradientStop(Colors.AliceBlue,1));
            graCollec.Add(new GradientStop(Colors.LightBlue, 0));
            pop.Child = new Border { Background = new LinearGradientBrush(graCollec) , BorderThickness = new Thickness(2), Child = uc };                                
            //pop.StaysOpen = true;
            pop.AllowsTransparency = true;
            pop.Placement = System.Windows.Controls.Primitives.PlacementMode.Center;                       
            pop.IsOpen = true;
            pop.Focus();        
        }

        private static void showReportToWindows(Window win, Uc_Trinhky uc,int showDialog, string tille)
        {
            uc.Margin = new Thickness(2, 2, 2, 2);
            GradientStopCollection graCollec = new GradientStopCollection();
            graCollec.Add(new GradientStop(Colors.AliceBlue, 1));
            graCollec.Add(new GradientStop(Colors.LightBlue, 0));
            win.Content = new Border { Background = new LinearGradientBrush(graCollec), BorderThickness = new Thickness(2), Child = uc };
            win.Title = tille;
            win.ShowInTaskbar = true;
            //pop.StaysOpen = true;
            if (showDialog == 1)
            {
                win.ShowDialog();
            }
            else
            {
                win.Show();
            }

        }
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Windows
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToWin(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly, string[] FieldsNames, string[] Formulas,string tille)
        {
            Window win = new Window();
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.WindowState = WindowState.Maximized;
            win.ShowInTaskbar = false;              
            Uc_Trinhky uc = new Uc_Trinhky(win, sender);
            uc.setinfor(rpttam, dvqly, FieldsNames, Formulas);
            sender.IsEnabled = false;
            showReportToWindows(win, uc,1,tille);            
           // win.Content = new Border { Background = new LinearGradientBrush(graCollec), BorderThickness = new Thickness(2), Child = uc }
        }
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Windows
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToWin(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly,string tille)
        {
            Window win = new Window();
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowInTaskbar = false;            
            win.WindowState = WindowState.Maximized;
            Uc_Trinhky uc = new Uc_Trinhky(win, sender);
            uc.setinfor(rpttam, dvqly);
            sender.IsEnabled = false;
            showReportToWindows(win, uc,1, tille);          
            // win.Content = new Border { Background = new LinearGradientBrush(graCollec), BorderThickness = new Thickness(2), Child = uc };

        }
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Windows
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToWin(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly, string[] FieldsNames, string[] Formulas,int Dialog,string tille)
        {
            Window win = new Window();
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.WindowState = WindowState.Maximized;
            win.ShowInTaskbar = false;
            Uc_Trinhky uc = new Uc_Trinhky(win, sender);
            uc.setinfor(rpttam, dvqly, FieldsNames, Formulas);
            sender.IsEnabled = false;
            showReportToWindows(win, uc, Dialog, tille);
            // win.Content = new Border { Background = new LinearGradientBrush(graCollec), BorderThickness = new Thickness(2), Child = uc }
        }
        /// <summary>
        /// DUNGPV - mở báo cáo bằng Windows
        /// </summary>
        /// <param name="sender">Trang gọi báo cáo</param>
        /// <param name="rpttam">Đối tượng báo cáo</param>
        /// <param name="dvqly">Mã đơn vị quản lý</param>
        public static void showReportToWin(UIElement sender, CrystalDecisions.CrystalReports.Engine.ReportDocument rpttam, string dvqly,int Dialog,string tille)
        {
            Window win = new Window();
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.ShowInTaskbar = false;
            win.WindowState = WindowState.Maximized;
            Uc_Trinhky uc = new Uc_Trinhky(win, sender);
            uc.setinfor(rpttam, dvqly);
            sender.IsEnabled = false;
            showReportToWindows(win, uc, Dialog,tille);
            // win.Content = new Border { Background = new LinearGradientBrush(graCollec), BorderThickness = new Thickness(2), Child = uc };

        }
    }
}
